﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using DeepTime.BootStrapper.UploadedImageMetaData;
using DeepTime.BootStrapper.Utilities;
using DeepTime.Shared.Entities;
using DeepTime.BootStrapper.DataModels;
using DeepTime.BootStrapper.DeepTimeImageMetaData;

namespace DeepTime.BootStrapper.Views
{
    public partial class DeepZoomImages : Page
    {
        public DeepZoomImages()
        {
            InitializeComponent();
            LoadDeepZooms();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void LoadDeepZooms()
        {
            DeepTimeImageMetaDataClient proxy = ServiceHelper.CreateDeepZoomImageMetaDataProxy();

            proxy.GetDeepZoomImagesCompleted += delegate(object sndr, GetDeepZoomImagesCompletedEventArgs args)
            {
                if (args.Error == null)
                {
                    lbImages.DataContext = args.Result.Select<DeepZoomImageMetaDataEntity, DeepZoomImageMetaDataDataModel>(entity => new DeepZoomImageMetaDataDataModel(entity));
                }
            };

            proxy.GetDeepZoomImagesAsync();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            DeepZoomImageMetaDataDataModel data = ((Button)sender).DataContext as DeepZoomImageMetaDataDataModel;
            NavigationService.Navigate(new Uri("/DeepZoomViewer?rowkey=" + data.RowKey + "&partitionkey=" + data.PartitionKey, UriKind.Relative));
        }
    }
}
